# -*- coding: utf-8 -*-
import os
from bratislava.logging.plogging import Plog
# 调试模式是否开启
DEBUG = True

SECRET_KEY = 'ty@puton.info'

logFormatDict = {
        'standard_format': '[%(asctime)s][%(threadName)s:%(thread)d][task_id:%(name)s][%(filename)s:%(lineno)d]' \
                           '[%(levelname)s][%(message)s]',  # 其中name为getlogger指定的名字
        'simple_format': '[%(levelname)s][%(asctime)s][%(filename)s:%(lineno)d]%(message)s',
        'id_simple_format': '[%(levelname)s][%(asctime)s] %(message)s',
        'simple_format_info': '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
    }
# 2.x
# try:
#     PROFILE = os.environ["SPD_PROFILE"]
# except Exception, e:
#     PROFILE = 'dev'

# 3.x
try:
    PROFILE = os.environ["SPD_PROFILE"]
except Exception as e:
    PROFILE = 'dev'

if PROFILE == 'dev':
    mysql2hive_task_db = 'mysql://pyspd_admin:pyspd_admin_1Q@192.168.100.161:3306/spd_mgr'
    es_ips = ['10.209.156.232', '10.209.156.233', '10.209.156.234']
    hive_url = 'hive://10.231.32.131:10000/sjtd?auth_mechanism=GSSAPI'
    data_json_dir = 'D:\iProject\spidermanager-master\datax\job'
    targetDefaultFS = 'hdfs://192.168.100.151:9000'
    hdfs_path = '/user/hive/warehouse/sjtd.db'
    loggerLevel = 'DEBUG:INFO'
    loggerFormat = 'standard_format'
    loggerDir = 'D:\iProject\spidermanager-master\synhive\logs'
    loggerFileName = 'sync_system.log'
    logFileName = loggerDir + os.sep + loggerFileName
    log = Plog()
    log.set_logger(when='D', limit=1, level=loggerLevel, filename=logFileName, mode='w', fmt=logFormatDict[loggerFormat])
    log = log.get_logger_instance()

    mysqlInfo = {
        "host": '192.168.100.161',
        "user": 'root',
        "passwd": 'newpasswd',
        "db": 'OLINGO',
        "port": 3306,
        "charset": 'utf8'
    }

    postgresInfo = {
        "host": '127.0.0.1',
        "user": 'postgres',
        "passwd": 'post',
        "db": 'postgres',
        "port": 5432,
        "charset": 'utf8'
    }

elif PROFILE == 'vm':
    mysql2hive_task_db = 'mysql://pyspd_admin:pyspd_admin_1Q@192.168.100.161:3306/spd_mgr'
    es_ips = ['10.209.156.232', '10.209.156.233', '10.209.156.234']
    hive_url = 'hive://10.231.32.131:10000/sjtd?auth_mechanism=GSSAPI'
    data_json_dir = os.path.expanduser('~') + '/app/datax/job'
    targetDefaultFS = 'hdfs://192.168.100.151:9000'
    hdfs_path = '/user/hive/warehouse/sjtd.db'
    loggerLevel = 'DEBUG:INFO'
    loggerFormat = 'standard_format'
    loggerDir = os.path.expanduser('~') + '/app/bratislava/logs'
    loggerFileName = 'sync_system.log'
    logFileName = loggerDir + os.sep + loggerFileName
    log = Plog()
    log.set_logger(when='D', limit=1, level=loggerLevel, filename=logFileName, mode='w', fmt=logFormatDict[loggerFormat])
    log = log.get_logger_instance()

    mysqlInfo = {
        "host": '192.168.100.161',
        "user": 'root',
        "passwd": 'newpasswd',
        "db": 'OLINGO',
        "port": 3306,
        "charset": 'utf8'
    }

    postgresInfo = {
        "host": '127.0.0.1',
        "user": 'postgres',
        "passwd": 'post',
        "db": 'postgres',
        "port": 5432,
        "charset": 'utf8'
    }

elif PROFILE == 'test':
    mysql2hive_task_db = 'mysql://pyspd_admin:pyspd_admin_1Q@192.168.100.161:3306/spd_mgr'
    es_ips = ['10.209.156.232', '10.209.156.233', '10.209.156.234']
    hive_url = 'hive://10.231.32.131:10000/sjtd?auth_mechanism=GSSAPI'
    data_json_dir = os.path.expanduser('~') + '/app/datax/job'
    targetDefaultFS = 'hdfs://192.168.100.151:9000'
    hdfs_path = '/user/hive/warehouse/sjtd.db'
    loggerLevel = 'DEBUG:INFO'
    loggerFormat = 'standard_format'
    loggerDir = os.path.expanduser('~') + '/app/bratislava/logs'
    loggerFileName = 'sync_system.log'
    logFileName = loggerDir + os.sep + loggerFileName
    log = Plog()
    log.set_logger(when='D', limit=1, level=loggerLevel, filename=logFileName, mode='w', fmt=logFormatDict[loggerFormat])
    log = log.get_logger_instance()

    mysqlInfo = {
        "host": '192.168.100.161',
        "user": 'root',
        "passwd": 'newpasswd',
        "db": 'OLINGO',
        "port": 3306,
        "charset": 'utf8'
    }

    postgresInfo = {
        "host": '127.0.0.1',
        "user": 'postgres',
        "passwd": 'post',
        "db": 'postgres',
        "port": 5432,
        "charset": 'utf8'
    }

elif PROFILE == 'prod':
    mysql2hive_task_db = 'mysql://root:py_spd@10.209.156.230:3306/spd_mgr'
    es_ips = ['10.209.156.232', '10.209.156.233', '10.209.156.234']
    hive_url = 'hive://10.231.32.131:10000/sjtd?auth_mechanism=GSSAPI'
    data_json_dir = os.path.expanduser('~') + '/app/datax/job'
    targetDefaultFS = 'hdfs://nameservice1'
    hdfs_path = '/user/hive/warehouse/sjtd.db'
    loggerLevel = 'DEBUG:INFO'
    loggerFormat = 'standard_format'
    loggerDir = os.path.expanduser('~') + '/app/bratislava/logs'
    loggerFileName = 'sync_system.log'
    logFileName = loggerDir + os.sep + loggerFileName
    log = Plog()
    log.set_logger(when='D', limit=1, level=loggerLevel, filename=logFileName, mode='w', fmt=logFormatDict[loggerFormat])
    log = log.get_logger_instance()

    mysqlInfo = {
        "host": '10.209.156.230',
        "user": 'root',
        "passwd": 'py_spd',
        "db": 'mysql',
        "port": 3306,
        "charset": 'utf8'
    }

    postgresInfo = {
        "host": '127.0.0.1',
        "user": 'postgres',
        "passwd": 'post',
        "db": 'postgres',
        "port": 5432,
        "charset": 'utf8'
    }

if __name__ == '__main__':
    # print(PROFILE)
    # print(data_json_dir)
    # log.info("test_setting_log")
    # print(logFileName)
    # file = __file__
    # print(file)
    # abs_file = os.path.abspath(file)
    # print(abs_file)
    # dir_file = os.path.dirname(abs_file)
    # print(dir_file)
    tb = u'tablename'
    db = u'databasename'
    # log.info('删除hive临时表:%s.%s', tb, db)

    num = 0

    lst = [tb, db, num]
    args = tuple(lst)
    print(args)
    ntplst = [e.encode('utf-8') if ['str', 'unicode'].__contains__(type(e).__name__) else e for e in args]
    print(ntplst)


    # s = 'abc'
    # print(type(s))
    # if type(s).__name__ == 'str':
    #     print(1)
    # else:
    #     print(2)

    # ls = ['str', 'unicode']
    # print(ls.__contains__('uniacode'))

